package com.by.basicgateway.dto;

import com.by.basicgateway.enums.RequestorClientTypeEnum;
import lombok.Getter;
import lombok.Setter;
import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;
import java.util.Map;

@Getter
@Setter
public class ByGatewayAuthentication extends AbstractAuthenticationToken {

    private String token;

    private Long userId;

    private RequestorClientTypeEnum requestorClientTypeEnum;

    private Boolean isAuthenticated;

    private Map<String, String> userDetail;

    public ByGatewayAuthentication(Long userId, String token) {
        super(null);
        this.token = token;
        this.userId = userId;
        setAuthenticated(false);
    }

    public ByGatewayAuthentication(Long userId, String token, Collection<? extends GrantedAuthority> authorities) {
        super(null);
        this.token = token;
        this.userId = userId;
        super.setAuthenticated(true); // must use super, as we override
    }

    /**
     * 此处凭证为token
     *
     * @return
     */
    @Override
    public String getCredentials() {
        return this.token;
    }

    /**
     * @return
     */
    @Override
    public Map<String, String> getDetails() {
        return this.userDetail;
    }

    /**
     * 用户详细信息,暂无
     *
     * @return
     */
    @Override
    public Long getPrincipal() {
        return this.userId;
    }

    /**
     * 是否认证成功
     *
     * @return
     */
    @Override
    public boolean isAuthenticated() {
        return this.isAuthenticated;
    }

    @Override
    public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException {
        this.isAuthenticated = isAuthenticated;
    }

    @Override
    public String getName() {
        return null;
    }

}
